package com.xszx.controller;

import com.xszx.entity.GoodInOutInfo;
import com.xszx.entity.Position;
import com.xszx.entity.Warehouse;
import com.xszx.entity.WarehouseRegionInfo;
import com.xszx.service.GoodService;
import com.xszx.service.WarehouseService;
import com.xszx.vo.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLOutput;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/good")
public class GoodController {
    @Autowired
    private GoodService goodService;
    @Autowired
    private WarehouseService warehouseService;

    //入库前回显仓库
    @RequestMapping("/getWarehousesByType")
    private AjaxJson getWarehousesByType(String type){
        AjaxJson ajaxJson = new AjaxJson();
        List<Warehouse> list = warehouseService.getWarehousesByType(type);
        String msg = list ==null?"获取失败":"";
        ajaxJson.setErrMsg(msg);
        ajaxJson.put("list",list);
        return ajaxJson;
    }

    //入库前回显仓库的区域(根据仓库的id)
    @RequestMapping("/getRegionByWid")
    private AjaxJson getRegionByWid(String wid){
        AjaxJson ajaxJson = new AjaxJson();
        List<WarehouseRegionInfo> list = warehouseService.getRegionByWid(wid);
        String msg = list ==null?"获取失败":"";
        ajaxJson.put("list",list);
        ajaxJson.setErrMsg(msg);
        return ajaxJson;
    }
    //通过区域id查询区域类型
    @RequestMapping("/positionList")
    private AjaxJson positionList(Integer r_id){
        AjaxJson ajaxJson = new AjaxJson();
        List<Position> list = warehouseService.getpositionList(r_id);
        String msg = list ==null?"获取失败":"";
        ajaxJson.put("list",list);
        ajaxJson.setErrMsg(msg);
        return ajaxJson;
    }

    //入库
    @RequestMapping("inWarehouse")
    private AjaxJson InWarehouse(@RequestBody GoodInOutInfo goodInOutInfo){
        System.out.println(goodInOutInfo);
        AjaxJson ajaxJson = new AjaxJson();
        String flag=goodService.inWarehouse(goodInOutInfo);
        ajaxJson.put("msg",flag);
        return ajaxJson;
    }
//    //获得入库记录表
//    @RequestMapping("getInWarehouseRecord")
//    private AjaxJson getInWarehouseRecord(){
//        AjaxJson ajaxJson = new AjaxJson();
//        List<GoodInOutInfo> list = goodService.getInWarehouseRecord();
//        ajaxJson.put("list",list);
//        return ajaxJson;
//    }


    //出库
    @RequestMapping(value = "outWarehouse", method = RequestMethod.POST)
    private AjaxJson outWarehouse(@RequestBody Map<String, Object> params) {
        Integer gid = (Integer) params.get("gid");
        Integer num = (Integer) params.get("num");
        AjaxJson ajaxJson = new AjaxJson();
        String ret = goodService.outWarehouse(gid,num);
        ajaxJson.put("msg",ret);
        return ajaxJson;
    }


//    //获得出库记录表
//    @RequestMapping("/getOutWarehouseRecord")
//    private AjaxJson getOutWarehouseRecord(){
//        AjaxJson ajaxJson = new AjaxJson();
//        List<GoodInOutInfo> list = goodService.getOutWarehouseRecord();
//        String msg = list==null?"获取失败":"";
//        ajaxJson.put("list",list);
//        ajaxJson.setErrMsg(msg);
//        return ajaxJson;
//    }


}
